package com.resourcestore.action;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.List;

import com.resourcestore.utils.CommonUtil;
import com.resourcestore.action.BaseAction;
import com.resourcestore.dao.MajorGroupDao;
import com.resourcestore.model.MajorGroup;
import com.resourcestore.utils.tag.Pagination;

public class ExpertMajorGroupAction extends BaseAction {
	
	private List<MajorGroup> listMajorGroup;
	private MajorGroupDao majorGroupDao = new MajorGroupDao();
	private MajorGroup majorGroup;
	private Pagination pagination = new Pagination();
	
	
	
	/**
	 * 专业群查询 带分页
	 * @throws ParseException 
	 * 
	 */
	public String listMajorGroupReadExpert(){
		majorGroup = new MajorGroup();
		pagination.setTotal(majorGroupDao.queryMajorGroupNum(majorGroup));
		listMajorGroup = majorGroupDao.selectMajorGroupPage(majorGroup,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listMajorGroup.size(); i++) {
				try {
					listMajorGroup.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listMajorGroup.get(i).getGmtCreated()));
					listMajorGroup.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listMajorGroup.get(i).getGmtModified()));
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		}
		
		return newpath("/ExpertMajorGroup/listMajorGroupRead.jsp");
	}
	
	
	/**
	 * 专业群搜索 带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListMajorGroupReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			majorGroup.setMajorgroupName(new String(majorGroup.getMajorgroupName().getBytes("iso-8859-1"),"UTF-8"));
			majorGroup.setMajorgroupRemark(new String(majorGroup.getMajorgroupRemark().getBytes("iso-8859-1"),"UTF-8"));
			majorGroup.setAuthor(new String(majorGroup.getAuthor().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		pagination.setTotal(majorGroupDao.queryMajorGroupNum(majorGroup));
		listMajorGroup = majorGroupDao.selectMajorGroupPage(majorGroup,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listMajorGroup.size(); i++) {
			try {
			listMajorGroup.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listMajorGroup.get(i).getGmtCreated()));
			listMajorGroup.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listMajorGroup.get(i).getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertMajorGroup/listMajorGroupRead.jsp");
	}
	
	
	public List<MajorGroup> getListMajorGroup() {
		return listMajorGroup;
	}
	public void setListMajorGroup(List<MajorGroup> listMajorGroup) {
		this.listMajorGroup = listMajorGroup;
	}

	public MajorGroup getMajorGroup() {
		return majorGroup;
	}

	public void setMajorGroup(MajorGroup majorGroup) {
		this.majorGroup = majorGroup;
	}

	public Pagination getPagination() {
		return pagination;
	}

	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}


}
